package org.example.spring_blog.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.example.spring_blog.enums.ResultCodeEnum;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {
    private int code;
    private String msg;
    private T data;

    public static <T> Result<T> success(T data) {
        Result<T> result=new Result<>();
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        result.setMsg("操作成功");
        result.setData(data);
        return result;
    }
    public static <T> Result<T> success() {
        return new Result<>(ResultCodeEnum.SUCCESS.getCode(), "操作成功",null);
    }
    public static <T> Result<T> fail(String msg) {
        return new Result<>(ResultCodeEnum.FAIL.getCode(), msg,null);
    }
    public static <T> Result<T> fail(String msg,T data) {
        return new Result<>(ResultCodeEnum.FAIL.getCode(),msg,data );
    }
    public static <T> Result<T> fail(int code,String msg) {
        return new Result<>(code,msg,null);
    }
    public static <T> Result<T> noLogin(String msg) {
        return new Result<>(ResultCodeEnum.NO_LOGIN.getCode(), msg,null);
    }
}
